//
//  MallClassifyContentViewController.m
//  xiaobaima
//
//  Created by xbmios on 2018/1/19.
//  Copyright © 2018年 xbmios. All rights reserved.
//

#import "MallClassifyContentViewController.h"
#import "SupportCategoryGoodListModel.h"
//#import "MallListTableViewCell.h"
//#import "MallListContentModel.h"
//#import "MallSearchViewController.h"


static NSString *tableviewID = @"MallClassifyContentViewControllerID";

@interface MallClassifyContentViewController () <UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate,UIScrollViewDelegate>

@property (strong, nonatomic) UISearchBar *searchBar;

@property (strong, nonatomic) UITableView *tableView;


@property (assign, nonatomic) NSInteger page;

//@property (nonatomic ,strong) TipView *tipView;

@property (strong, nonatomic) NSMutableArray *contentArr;

//@property (copy, nonatomic) NSString *totolCount;

//@property (strong, nonatomic) UIView *bg1;

@end

@implementation MallClassifyContentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = Colorf2f2f2;

    self.page = 1;

    [self setupUI];

    MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    [footer setTitle:@"" forState:MJRefreshStateIdle];
    [footer setTitle:@"正在加载。。。。" forState:MJRefreshStateRefreshing];
    [footer setTitle:@"亲，没有数据了" forState:MJRefreshStateNoMoreData];
    footer.stateLabel.font = Font(17);
    footer.stateLabel.textColor = Color999999;
    self.tableView.mj_footer = footer;
    self.tableView.mj_footer.hidden = NO;

    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
    [header beginRefreshing];
    [header setTitle:@"下拉可以刷新!" forState:MJRefreshStateIdle];
    [header setTitle:@"松手立即刷新!" forState:MJRefreshStatePulling];
    [header setTitle:@"正在加载..." forState:MJRefreshStateRefreshing];
    header.stateLabel.font = Font(24);
    header.stateLabel.textColor = Color999999;
    header.lastUpdatedTimeLabel.hidden = YES;
    self.tableView.mj_header = header;


}

#pragma mark 下拉刷新数据
- (void)loadNewData
{

    self.page = 1;
    [self.tableView.mj_footer resetNoMoreData];
    [self.tableView reloadData];
    [self.tableView.mj_header endRefreshing];

}

- (void)loadMoreData {

    self.page ++;

        // 刷新表格
        [self.tableView reloadData];
        [self.tableView.mj_footer endRefreshing];

}

- (void)setupUI {

    [self.view addSubview:self.tableView];


    __weak typeof(self) weakSelf = self;
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.view.mas_left);
        make.right.mas_equalTo(weakSelf.view.mas_right);
        make.top.mas_equalTo(weakSelf.view.mas_top);
        make.bottom.mas_equalTo(weakSelf.view.mas_bottom);
        
    }];



}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    return jisuan(240);

}

#pragma mark -tableview Delegate / Datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.contentArr.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableviewID forIndexPath:indexPath];

    return cell;

}

#pragma mark -懒加载
- (UITableView *)tableView {

    if (_tableView == nil) {

        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.clipsToBounds = NO;
        
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;

        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:tableviewID];

        if (@available(iOS 11, *)) {

            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;

        }

    }

    return _tableView;
}

//- (UISearchBar *)searchBar {
//
//    if (_searchBar == nil) {
//
//        _searchBar = [[UISearchBar alloc] init];
//        _searchBar.delegate = self;
//        _searchBar.barStyle = UIBarStyleDefault;
//        _searchBar.showsCancelButton = NO;
//
//        //拿到searchBar的输入框
//        UITextField *searchTextField = [_searchBar valueForKey:@"_searchField"];
//        //输入框背景颜色
//        searchTextField.backgroundColor = [UIColor colorWithRed:234/255.0 green:235/255.0 blue:237/255.0 alpha:1];
//        searchTextField.layer.cornerRadius = jisuan(30);
//        searchTextField.layer.masksToBounds = YES;
//
////        _searchBar.barTintColor = colorefefef;
//        _searchBar.backgroundImage = [[UIImage alloc] init];
//    }
//
//    return _searchBar;
//}
//
////- (TipView *)tipView {
////
////    if (_tipView == nil) {
////        _tipView = [[TipView alloc] initWithImage:@"wujilu2" andText:@"暂无记录" showButton:NO andBtnAction:nil];;
////    }
////    return _tipView;
////}
//
//- (NSMutableArray *)contentArr {
//
//    if (_contentArr == nil) {
//
//        _contentArr = [NSMutableArray array];
//
//    }
//
//    return _contentArr;
//}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = NO;
    
//    [self.navigationController setNavigationBarHidden:NO animated:YES];
    
//    self.tabBarController.tabBar.hidden = YES;
    
//    self.bg1.alpha = [CommonAction sharedInstance].isHidden3;
    
}

- (void)viewWillDisappear:(BOOL)animated {
    
    [super viewWillDisappear:animated];
    
//    self.navigationController.navigationBar.hidden = YES;
//    
////    [self.navigationController setNavigationBarHidden:YES animated:YES];
//    
//    self.tabBarController.tabBar.hidden = NO;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
